package com.boss.salary.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.boss.asset.service.IAssetInfoService;
import com.boss.common.entity.PageDTO;
import com.boss.common.service.ICommonService;
import com.boss.common.util.DateUtils;
import com.boss.config.FileServiceConfiguration;
import com.boss.framework.dto.PaginationDTO;
import com.boss.framework.exception.AppRuntimeException;
import com.boss.salary.constant.ApiElementConstant;
import com.boss.salary.constant.SystemDictConstant;
import com.boss.salary.dao.*;
import com.boss.salary.entity.AgencyVerify;
import com.boss.salary.entity.ExportBankType;
import com.boss.salary.service.IGenerateBankDataService;
import com.boss.salary.vo.AgencySalaryVO;
import com.boss.salary.vo.SalaryDataVo;
import com.boss.sys.ca.user.dto.UserDTO;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class GenerateBankDataServiceImpl implements IGenerateBankDataService {

    private static final Logger LOG = LoggerFactory.getLogger(GenerateBankDataServiceImpl.class);
    /**
     * 引入接口服务配置类
     */
    @Autowired
    private FileServiceConfiguration fileServiceConfiguration;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ICommonService commonService;

    @Autowired
    private IGenerateBankDataDao generateBankDataDao;
    @Autowired
    private IAgencyVerifyDao agencyVerifyDao;
    @Autowired
    private IAgencySalaryDao agencySalaryDao;
    @Autowired
    private IAgencyInfoDao agencyInfoDao;
    @Autowired
    private ISalaryMonthEndDao salaryMonthEndDao;
    @Autowired
    private IFileSendLogDao fileSendLogDao;
    @Autowired
    private ISalaryBasedataDao salaryBasedataDao;
    @Autowired
    private IPayeeAcctDao payeeAcctDao;
    @Autowired
    private IAssetInfoService assetInfoService;
    @Autowired
    private IExportBankTypeDao exportBankTypeDao;

    @Override
    public PageDTO<SalaryDataVo> getGenerateBankDataPage(PaginationDTO paginationDTO, Map<String, Object> queryForm, UserDTO userDTO) {
        PageDTO<SalaryDataVo> pageDTO = new PageDTO<>();
//        if(StringUtils.isEmpty(queryForm.get("salaCardBank"))){//若未传银行参数，择不显示任何内容
//            return pageDTO;
//        }
        List<String> agencyIds;
        if(StringUtils.isEmpty(queryForm.get("agencyId"))){
            agencyIds = commonService.getAgencyChildrenId(userDTO, "0");
        }else{
            String parentId = String.valueOf(queryForm.get("agencyId"));
            agencyIds = commonService.getAgencyChildrenId(userDTO, parentId);
        }
        queryForm.put("province",userDTO.getProvince());
        List<SalaryDataVo> salaryDataVoList = generateBankDataDao.selectGenerateBankDataPage(paginationDTO, agencyIds, queryForm);
//        if (!CollectionUtils.isEmpty(salaryDataVoList)) {
////            如果不为空则计算并插入合计值
//            SalaryDataVo salaryDataVo = generateBankDataDao.selectGenerateBankDataSum(agencyIds, queryForm);
//            salaryDataVoList.add(0, salaryDataVo);
//        }
        int total = generateBankDataDao.selectGenerateBankDataTotal(agencyIds, queryForm);

        pageDTO.setRows(salaryDataVoList);
        pageDTO.setTotal(total);
        return pageDTO;
    }

    @Override
    public PageDTO<Map<String, Object>> getPersonSalaryInfoPage(UserDTO userDTO,PaginationDTO paginationDTO, Map<String, Object> queryForm) {
        List<Map<String, Object>> result = Collections.emptyList();
        PageDTO<Map<String, Object>> pageDTO = new PageDTO<>();
        pageDTO.setRows(result);
        pageDTO.setTotal(0);
        String agencyId;
        if(CollectionUtils.isEmpty(queryForm) || StringUtils.isEmpty(queryForm.get("agencyId"))){
            return pageDTO;
        }else{
            agencyId = String.valueOf(queryForm.get("agencyId"));
        }
//        查询当前月份，送审状态及工资变动状态
        Map<String,Object> stateMap = agencyVerifyDao.selectStateByAgencyId(agencyId,"0","salary_month");
//        当月月份
        String salaryMonth = String.valueOf(stateMap.get("salary_month"));
//        获取当月工资字段名
        List<AgencySalaryVO> currentcolumnList = agencySalaryDao.selectColumnName(userDTO);
        if(CollectionUtils.isEmpty(currentcolumnList)){
            throw new AppRuntimeException("存在工资项目挂接未设置！请联系管理员进行设置！");
        }
        List<String> salaryColumns = currentcolumnList.stream().map(AgencySalaryVO::getColumnName).collect(Collectors.toList());
        List<String> salaryIds = currentcolumnList.stream().map(AgencySalaryVO::getSalaryId).collect(Collectors.toList());
//      获取当月salaryID对应字段名map
        Map<String,String> currentSalaryIdJoinColumnMap = currentcolumnList.stream()
                .collect(Collectors.toMap(AgencySalaryVO::getSalaryId, AgencySalaryVO::getColumnName));
//查询编报数据
        result = salaryMonthEndDao.selectPersonSalaryInfoPage(
                paginationDTO, agencyId, salaryIds, salaryMonth, currentSalaryIdJoinColumnMap, queryForm);
        if(!CollectionUtils.isEmpty(result)){
            int total = salaryMonthEndDao.selectPersonSalaryInfoTotal(agencyId, queryForm);
            //计算各个工资项合计值
//            Map<String, Object> salaryMonthEndSum = agencySalaryDao.selectSalaryMonthEndSum(
//                    agencyId, SystemDictConstant.IS_FALSE, salaryColumns, queryForm,null);
//            salaryMonthEndSum.put("index", "合计");
//            result.add(0, salaryMonthEndSum);
//            设置返回值
            pageDTO.setRows(result);
            pageDTO.setTotal(total);
        }
        return pageDTO;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void uploadBankData(String province,String sendBankCode) throws AppRuntimeException {
        JSONObject json = uploadSalaryData(province,sendBankCode);
        String rscode = String.valueOf(json.get("rscode"));
        if(SystemDictConstant.SUCCESS_CODE.equals(rscode)){
            List<AgencyVerify> agencyVerify = agencyVerifyDao.getAgencyVerifyBySalaryBank(sendBankCode,province);
//            agencyVerify.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
//            agencyVerify.setIsBankDataCreated(SystemDictConstant.IS_TRUE);
            agencyVerifyDao.batchUpdateAgencyVerifyBankStatus(agencyVerify,"1");
        }else{
            String message = String.valueOf(json.get("result"));
            LOG.warn("上传银行工资数据：{}",message);
            throw new AppRuntimeException(message);
        }


    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject uploadSalaryData(String province,String sendBankCode) throws AppRuntimeException {
        String url = fileServiceConfiguration.getFileservice()+"/v1/salary/salaryFile";
        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
        paramMap.add("province", province);
        paramMap.add("sendBankCode", sendBankCode);//生成文件银行编码
        HttpHeaders headers = new HttpHeaders();
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(paramMap, headers);
        JSONObject json = restTemplate.postForEntity(url, httpEntity, JSONObject.class).getBody();
        if(!StringUtils.isEmpty(json) && !StringUtils.isEmpty(json.get("rscode"))){
            return json;
        }else{
            LOG.warn("未请求到文件服务或文件服务返回值异常！");
            throw new RuntimeException("请求文件服务失败！");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void regenerateBankData(String province,String sendBankCode) throws AppRuntimeException {
//        调用文件生成服务
        JSONObject json = generateSalaryData(province,sendBankCode);
        String rscode = String.valueOf(json.get("rscode"));
        if(SystemDictConstant.SUCCESS_CODE.equals(rscode)){
            List<AgencyVerify> agencyVerify = agencyVerifyDao.getAgencyVerifyBySalaryBank(sendBankCode,province);
            agencyVerifyDao.batchUpdateAgencyVerifyBankStatus(agencyVerify,"0");
        }else{
            String message = String.valueOf(json.get("result"));
            LOG.warn("重新生成银行工资数据：{}",message);
            throw new AppRuntimeException(message);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject generateSalaryData(String province,String sendBankCode) throws AppRuntimeException {
        String url = fileServiceConfiguration.getFileservice()+"/v1/salary/generateSalaryFile";
        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
        paramMap.add("province", province);
        paramMap.add("sendBankCode", sendBankCode);//生成文件银行编码
        HttpHeaders headers = new HttpHeaders();
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(paramMap, headers);
        JSONObject json = restTemplate.postForEntity(url, httpEntity, JSONObject.class).getBody();
        if(!StringUtils.isEmpty(json) && !StringUtils.isEmpty(json.get("rscode"))){
            return json;
        }else{
            LOG.warn("未请求到文件服务或文件服务返回值异常！");
            throw new RuntimeException("请求文件服务失败！");
        }
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void ungenerateBankData(String province,String sendBankCode) throws AppRuntimeException {
//        调用文件生成服务
        JSONObject json = ungenerateSalaryData(province,sendBankCode);
        String rscode = String.valueOf(json.get("rscode"));
        if(SystemDictConstant.SUCCESS_CODE.equals(rscode)){
            List<AgencyVerify> agencyVerify = agencyVerifyDao.getAgencyVerifyBySalaryBank(sendBankCode,province);
            agencyVerifyDao.batchUpdateAgencyVerifyBankStatus(agencyVerify,"0");
        }else{
            String message = String.valueOf(json.get("result"));
            LOG.warn("撤销生成银行工资数据：{}",message);
            throw new AppRuntimeException(message);
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject ungenerateSalaryData(String province,String sendBankCode) throws AppRuntimeException {
        String url = fileServiceConfiguration.getFileservice()+"/v1/salary/ungenerateSalaryFile";
        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
        paramMap.add("province", province);
        paramMap.add("sendBankCode", sendBankCode);//生成文件银行编码
        HttpHeaders headers = new HttpHeaders();
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(paramMap, headers);
        JSONObject json = restTemplate.postForEntity(url, httpEntity, JSONObject.class).getBody();
        if(!StringUtils.isEmpty(json) && !StringUtils.isEmpty(json.get("rscode"))){
            return json;
        }else{
            LOG.warn("未请求到文件服务或文件服务返回值异常！");
            throw new RuntimeException("请求文件服务失败！");
        }
    }

    @Override
    public void generateBankData(String province,Map<String,Object> queryForm) throws AppRuntimeException {
        List<String> agencyIds=agencyInfoDao.getAgencyIdsByBank(queryForm);
//        调用文件生成服务
        JSONObject json = generateSalaryData(province,queryForm.get("salaCardBank").toString());
        String rscode = String.valueOf(json.get("rscode"));
        if(!SystemDictConstant.SUCCESS_CODE.equals(rscode)){
            String message = String.valueOf(json.get("result"));
            LOG.warn("生成银行工资数据：{}",message);
            throw new AppRuntimeException(message);
        }
        for(String agencyid:agencyIds){
            AgencyVerify agencyVerify = new AgencyVerify();
            agencyVerify.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
            agencyVerify.setIsBankDataCreated(SystemDictConstant.IS_GENERTE_NO_SEND);
            agencyVerify.setAgencyId(agencyid);
            agencyVerifyDao.updateAgencyState(agencyVerify,province);
        }

    }

    @Override
    public boolean verifyFileState(String province) {
        int count = fileSendLogDao.selectNoSendFileCount(province);
        return count > 0;
    }

    /**
     * 导出银行文件查询明细
     * @param userDTO
     * @param outputStream
     * @throws IOException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void generateBankDataService(UserDTO userDTO, OutputStream outputStream) throws IOException {
//        工资编码list
        List<AgencySalaryVO> agencySalarys = salaryBasedataDao.selectSalaryItemByProvince(userDTO.getProvince());
        //获取工资项Code
        List<String> salaryCodeList = agencySalarys.stream().map(AgencySalaryVO::getSalaryCode).collect(Collectors.toList());
        //获取工资项Name
        List<String> salaryNameList = agencySalarys.stream().map(AgencySalaryVO::getSalaryName).collect(Collectors.toList());
        //获取导出保存模板的银行
        List<ExportBankType> exportBankList=exportBankTypeDao.getExportBankList(userDTO.getProvince());
        //从平台接口获取银行编码和名称
        List<Map<String,String>> payeeAccts = assetInfoService.getBaseDataSelect(ApiElementConstant.SALBANK,userDTO.getProvince());
        List<AgencySalaryVO> agencySalaryList = agencySalaryDao.selectColumnName(userDTO, salaryCodeList);

        List<String> currentColumnList = agencySalaryList.stream().map(AgencySalaryVO::getColumnName).collect(Collectors.toList());
        //获取可以生成得所有人员工资信息
        List<Map<String,Object>> list = salaryMonthEndDao.selectMXOffer(userDTO.getProvince(), currentColumnList);
        Map<String, Sheet> bankJoinOfferMap = new HashMap<>();
        Workbook workbook = new HSSFWorkbook();
        for(Map<String,String> payeeAcct : payeeAccts){
            String salaCardCode = payeeAcct.get("code");
            //建一个ExportBankType类型的List
            List<ExportBankType> exportBankLists=new ArrayList<>();
            for(ExportBankType exportBankType:exportBankList){
                //银行做的code做对比相等存入list中
                if(payeeAcct.get("code").equals(exportBankType.getBankType())){
                    exportBankLists.add(exportBankType);
                    }
            }
            String bankName = payeeAcct.get("name");
            Sheet sheet = workbook.createSheet(bankName);
            Row row = sheet.createRow(0);
            bankJoinOfferMap.put(salaCardCode, sheet);
            //判断银行的list是否为空如果是空走默认的的银行列表头，如果不为空走银行自己配置的列表头
            if(exportBankLists.size()>0){
                for(int i = 0; i < exportBankLists.size(); i++){
                    Cell cell = row.createCell(i, CellType.STRING);
                    //表头行
                    cell.setCellValue(exportBankLists.get(i).getSalaryName());
                }

            }else {
                //写死默认的表头人员信息
                for(int i = 0; i < 10; i++){
                Cell cell = row.createCell(i, CellType.STRING);
                switch (i){
                    case 0: cell.setCellValue("temp1"); break;
                    case 1: cell.setCellValue("单位编码"); break;
                    case 2: cell.setCellValue("单位名称"); break;
                    case 3: cell.setCellValue("部门编码"); break;
                    case 4: cell.setCellValue("工资性质名称"); break;
                    case 5: cell.setCellValue("级别内排序序号"); break;
                    case 6: cell.setCellValue("人员编码"); break;
                    case 7: cell.setCellValue("工资卡号"); break;
                    case 8: cell.setCellValue("姓名"); break;
                    case 9: cell.setCellValue("身份证号码"); break;
                 }
                 }
                //循环默认的人员工资项列
                for(int i = 0; i < salaryNameList.size(); i++){
                Cell cell = row.createCell(i + 10, CellType.STRING);
                cell.setCellValue(salaryNameList.get(i));
            }
            bankJoinOfferMap.put(salaCardCode, sheet);
            }
        }

        if(!CollectionUtils.isEmpty(list)) {
            //循环所有人的工资项
            for(Map<String, Object> offer : list) {
                String salaCardBank = String.valueOf(offer.get("salaCardBank"));
                List<ExportBankType> exportBankLists=new ArrayList<>();
                for(ExportBankType exportBankType:exportBankList){
                    //银行做匹配
                    if(salaCardBank.equals(exportBankType.getBankType())){
                        exportBankLists.add(exportBankType);
                    }
                }
                Sheet sheet = bankJoinOfferMap.get(salaCardBank);
                int rowIndex = sheet.getPhysicalNumberOfRows();
                Row row = sheet.createRow(rowIndex);
                //看当前银行是>0 大于走银行明细配置保存的 否则走默认的
                if(exportBankLists.size()>0){
                for(int i = 0; i < exportBankLists.size(); i++){
                    Cell cell = row.createCell(i, CellType.STRING);
                   // 和保存的工资项做匹配值
                    String column = String.valueOf(offer.get(exportBankLists.get(i).getColumnName()));
                    if("0".equals(column)){
                        //值等于0赋值为0
                        cell.setCellValue("0");
                    }else{
                        //如果有值获取匹配值 存入cell中
                        cell.setCellValue(String.valueOf(offer.get(exportBankLists.get(i).getColumnName())));
                    }
                }
                }else {
                    //默认保存的工资项
                    for(int i = 0; i < 10; i++){
                        Cell cell = row.createCell(i, CellType.STRING);
                        switch (i){
                            case 0: cell.setCellValue("D"); break;
                            case 1: cell.setCellValue(String.valueOf(offer.get("agencyCode"))); break;
                            case 2: cell.setCellValue(String.valueOf(offer.get("agencyName"))); break;
                            case 3: cell.setCellValue(String.valueOf(offer.get("state"))); break;
                            case 4: cell.setCellValue(String.valueOf(offer.get("meritPayCode"))); break;
                            case 5: cell.setCellValue(String.valueOf(offer.get("salaGrCode"))); break;
                            case 6: cell.setCellValue(String.valueOf(offer.get("personCode"))); break;
                            case 7: cell.setCellValue(String.valueOf(offer.get("salaCardNo"))); break;
                            case 8: cell.setCellValue(String.valueOf(offer.get("personName"))); break;
                            case 9: cell.setCellValue(String.valueOf(offer.get("idenNo"))); break;
                        }
                    }
                    for(int i = 0; i < currentColumnList.size(); i++){
                        Cell cell = row.createCell(i + 10, CellType.STRING);
                        String column = currentColumnList.get(i);
                        if("0".equals(column)){
                            cell.setCellValue("0");
                        }else{
                            cell.setCellValue(String.valueOf(offer.get(column)));
                        }
                    }
                }
            }
        }
        workbook.write(outputStream);
        outputStream.close();
//        修改银行数据生成状态
        AgencyVerify agencyVerify = new AgencyVerify();
        agencyVerify.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
        agencyVerify.setIsBankDataCreated(SystemDictConstant.IS_TRUE);
        agencyVerifyDao.updateAgencyState(agencyVerify,userDTO.getProvince());













//        Map<String, Sheet> bankJoinOfferMap = new HashMap<>();
//        Workbook workbook = new HSSFWorkbook();
//        for(Map<String,String> payeeAcct : payeeAccts){
//            String salaCardCode = payeeAcct.get("code");
//            String bankName = payeeAcct.get("name");
//            Sheet sheet = workbook.createSheet(bankName);
//            Row row = sheet.createRow(0);
//            for(int i = 0; i < 10; i++){
//                Cell cell = row.createCell(i, CellType.STRING);
//                switch (i){
//                    case 0: cell.setCellValue("temp1"); break;
//                    case 1: cell.setCellValue("单位编码"); break;
//                    case 2: cell.setCellValue("单位名称"); break;
//                    case 3: cell.setCellValue("部门编码"); break;
//                    case 4: cell.setCellValue("工资性质名称"); break;
//                    case 5: cell.setCellValue("级别内排序序号"); break;
//                    case 6: cell.setCellValue("人员编码"); break;
//                    case 7: cell.setCellValue("工资卡号"); break;
//                    case 8: cell.setCellValue("姓名"); break;
//                    case 9: cell.setCellValue("身份证号码"); break;
//                }
//            }
//            for(int i = 0; i < salaryNameList.size(); i++){
//                Cell cell = row.createCell(i + 10, CellType.STRING);
//                cell.setCellValue(salaryNameList.get(i));
//            }
//            bankJoinOfferMap.put(salaCardCode, sheet);
//        }
//        List<AgencySalaryVO> agencySalaryList = agencySalaryDao.selectColumnName(userDTO, salaryCodeList);
//        List<String> currentColumnList = agencySalaryList.stream().map(AgencySalaryVO::getColumnName).collect(Collectors.toList());
//        //获取可以生成得所有人员工资信息
//        List<Map<String,Object>> list = salaryMonthEndDao.selectMXOffer(userDTO.getProvince(), currentColumnList);
//
//            if(!CollectionUtils.isEmpty(list)) {
//                for(Map<String, Object> offer : list) {
//                    String salaCardBank = String.valueOf(offer.get("salaCardBank"));
//                    Sheet sheet = bankJoinOfferMap.get(salaCardBank);
//                    int rowIndex = sheet.getPhysicalNumberOfRows();
//                    Row row = sheet.createRow(rowIndex);
//                    for(int i = 0; i < 10; i++){
//                        Cell cell = row.createCell(i, CellType.STRING);
//                        switch (i){
//                            case 0: cell.setCellValue("D"); break;
//                            case 1: cell.setCellValue(String.valueOf(offer.get("agencyCode"))); break;
//                            case 2: cell.setCellValue(String.valueOf(offer.get("agencyName"))); break;
//                            case 3: cell.setCellValue(String.valueOf(offer.get("state"))); break;
//                            case 4: cell.setCellValue(String.valueOf(offer.get("meritPayCode"))); break;
//                            case 5: cell.setCellValue(String.valueOf(offer.get("salaGrCode"))); break;
//                            case 6: cell.setCellValue(String.valueOf(offer.get("personCode"))); break;
//                            case 7: cell.setCellValue(String.valueOf(offer.get("salaCardNo"))); break;
//                            case 8: cell.setCellValue(String.valueOf(offer.get("personName"))); break;
//                            case 9: cell.setCellValue(String.valueOf(offer.get("idenNo"))); break;
//                        }
//                    }
//                    for(int i = 0; i < currentColumnList.size(); i++){
//                        Cell cell = row.createCell(i + 10, CellType.STRING);
//                        String column = currentColumnList.get(i);
//                        if("0".equals(column)){
//                            cell.setCellValue("0");
//                        }else{
//                            cell.setCellValue(String.valueOf(offer.get(column)));
//                        }
//                    }
//                }
//            }
//
//        workbook.write(outputStream);
//        outputStream.close();
////        修改银行数据生成状态
//        AgencyVerify agencyVerify = new AgencyVerify();
//        agencyVerify.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
//        agencyVerify.setIsBankDataCreated(SystemDictConstant.IS_TRUE);
//        agencyVerifyDao.updateAgencyState(agencyVerify,userDTO.getProvince());
    }

    @Override
    public List<Map<String, Object>> getGenerateMessage(Map<String, Object> queryForm, UserDTO userDTO) {
        List<Map<String, Object>> requestList=new ArrayList<>();
        if(StringUtils.isEmpty(queryForm.get("salaCardBank"))&&StringUtils.isEmpty(queryForm.get("menuid"))){//若未传银行参数，择不显示任何内容
            return requestList;
        }
        List<String> agencyIds;
        if(StringUtils.isEmpty(queryForm.get("agencyId"))){
            agencyIds = commonService.getAgencyChildrenId(userDTO, "0");
        }else{
            String parentId = String.valueOf(queryForm.get("agencyId"));
            agencyIds = commonService.getAgencyChildrenId(userDTO, parentId);
        }
        if(!StringUtils.isEmpty(queryForm.get("agencySelected"))){
            agencyIds= Arrays.asList(queryForm.get("agencySelected").toString().split(","));
        }
        queryForm.put("province",userDTO.getProvince());

        // 查询生成信息
        requestList = generateBankDataDao.getGenerateMessage( queryForm,agencyIds);
        return requestList;
    }
}
